<template>
  <!-- 大客户项目跟进管理->延续审核 -->
  <div>
    <!-- 搜索 -->
    <TopFilter
      :list="topFilterInit"
      :cols="3"
      labelWidth="90"
      @filterChange="changeHandle"
      @onCollapse="collapseHandle"
    ></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchParams"
      :isSelectColumn="isSelectColumn"
      :params="flterValue"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
     >
      <template slot="controls" >
        <el-button size="small" type="primary" icon="el-icon-plus" @click="detailHandle(123,'edit')">编辑</el-button>
        <el-button size="small" type="primary" icon="el-icon-plus" @click="detailHandle(123,'info')">详情</el-button>
      </template>
    </FilterTable>
    <Drawer
      ref="infoDrawer"
      :visible.sync="visibleDrawer"
      title="延续审核"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <info-modal v-model="infoId" :infoType="type" @close="infoClose" />
    </Drawer>
    <!-- 经销商弹窗 -->
    <BaseDialog
      title="经销商查询"
      :visible.sync="visibleDealer"
      width="1000px"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <dealer-madal ref="dealerDialog" @close="closeDealer" />
    </BaseDialog>
  </div>
</template>
<script>
import dealerMadal from '../../clue/areaBossPush/dealerMadal';
import infoModal from '../failure/info';
import { dictionary } from '@/utils/dictMixin';
export default {
  mixins: [dictionary],
  components: {
    infoModal,
    dealerMadal
  },
  data() {
    return {
      visibleDrawer: false,
      isSelectColumn: false,
      visibleDealer: false,
      topFilterInit: this.topFilterInitFun(),
      infoId: '', //记录行id
      type: 'add', //add编辑 ，info详情
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: null //ipa 接口
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    //搜索数据
    topFilterInitFun() {
      return [
        
        { type: 'INPUT', label: '客户公司名称', fieldName: 'field1', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '项目名称', fieldName: 'field2', placeholder: '请选择', initialValue: '' },
        { type: 'SELECT', label: '项目跟进状态', fieldName: 'field3', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1008') },
        {
          type: 'RANGE_DATE',
          label: '延续申请日期',
          fieldName: 'DATE',
          valueFormat: 'yyyy-MM-dd', //返回数据格式
          initialValue: ['2019-08-12', '2019-09-18'],
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: '经销商',
          fieldName: 'field9',
          placeholder: '请选择',
          initialValue: '',
          unitRender: () => {
            return <el-button slot="append" icon="el-icon-search" onClick={() => this.dealerHandle()}></el-button>;
          }
        },
        { type: 'SELECT', label: '审批状态', fieldName: 'field5', placeholder: '请选择', initialValue: '', itemList: this.createDictList('1008') }
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.flterValue = val;
      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row,'edit')}>编辑 </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={() => this.detailHandle(props.row,'info')}>明细</el-button>
              </div>
            );
          }
        },
        
        {
          title: '项目跟进状态',
          dataIndex: 'field0',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }
        },
        {
          title: '审批状态',
          dataIndex: 'field1',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }
        },
        { title: '客户公司名称', dataIndex: 'field2', sorter: true },
        { title: '项目名称', dataIndex: 'field01', sorter: true },
        { title: '项目编号', dataIndex: 'field02', sorter: true },
        { title: '经销商', dataIndex: 'field03', sorter: true },
        { title: '区域经理', dataIndex: 'field3', sorter: true },
        { title: '延续原因', dataIndex: 'field5', sorter: true },
        { title: '申请时间', dataIndex: 'field6', sorter: true },
        { title: '审核时间', dataIndex: 'field9', sorter: true },
        { title: '审核人', dataIndex: 'field91', sorter: true },
        { title: '审核意见', dataIndex: 'field10', sorter: true }
      ];
    },
    //详情
    detailHandle(row, type) {
      //逻辑自己写
      this.visibleDrawer = true;
      this.infoId = 1000;
      this.type =type;
    },
    //关闭详情
    infoClose() {
      this.visibleDrawer = false;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    dealerHandle() {
      this.visibleDealer = true;
    },
    closeDealer(data) {
      this.visibleDealer = data.visible;
      this.topFilterInit[8].initialValue = '经销商名';
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    }
  }
};
</script>

<style lang="less" scoped>
</style>
